package cn.com.tianpeidong.restaurantadmin.project.admin.pos.rest;

import cn.com.tianpeidong.restaurantadmin.common.util.page.PageWrapper;
import cn.com.tianpeidong.restaurantadmin.project.admin.pos.entity.Payment;
import cn.com.tianpeidong.restaurantadmin.project.admin.pos.service.IPaymentService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.xml.ws.Response;
import java.util.List;

/**
 * @author tianpeidong
 * @version 创建时间: 19-6-2 下午2:23
 */
@RestController
@RequestMapping("/payment")
public class PaymentController {

    @Autowired
    private IPaymentService paymentService;

    @GetMapping
    @RequiresPermissions("payment:list")
    public ResponseEntity list(@RequestParam(value = "pagi") boolean isPagi,
                               @RequestParam(value = "per_page", required = false) Integer pageSize,
                               @RequestParam(value = "page", required = false) Integer page) {
        PageWrapper pageWrapper = new PageWrapper(pageSize, page);
        List<Payment> dishesList = paymentService.listPayment(new Payment());
        return ResponseEntity.ok(pageWrapper.getResult(dishesList));
    }

    @GetMapping("/get")
    @RequiresPermissions("payment:list")
    public ResponseEntity getPayment(@RequestParam("id") Long id) {
        return ResponseEntity.ok(paymentService.getPayment(id));
    }

    @PostMapping
    @RequiresPermissions("payment:add")
    public ResponseEntity newPayment(@RequestParam("saleId") Long saleId) {
        return ResponseEntity.ok(paymentService.newPayment(saleId));
    }

    @PutMapping
    @RequiresPermissions("payment:edit")
    public ResponseEntity makePayment(@RequestBody Payment payment) {
        return ResponseEntity.ok(paymentService.makePayment(payment));
    }

    @PatchMapping
    public ResponseEntity suspendPayment(@RequestParam("id") Long paymentId) {
        paymentService.suspendPayment(paymentId);
        return ResponseEntity.ok().build();
    }

    @PatchMapping("/calChange")
    public ResponseEntity calChange(@RequestBody Payment payment) {
        return ResponseEntity.ok(paymentService.calChange(payment));
    }

}
